<template>
  <div></div>
</template>

<script>
  import {take, map,mergeAll} from 'rxjs/operators'  //注意merge是静态的,mergeAll是实例主导的
  import {fromEvent, interval, merge} from 'rxjs'

  /*
  *
*/
  export default {
    name: "map-merge-all",
    mounted() {
      const clicks = fromEvent(document, 'click');
      const higherOrder = clicks.pipe(map((ev) => interval(1000))); //高阶函数

      higherOrder.subscribe(x => {
        console.log('in high order',typeof x,x);
        x.subscribe(nest => console.log('nested',nest))  ///不扁平化,则使用嵌套
      });
      const firstOrder = higherOrder.pipe(mergeAll()); //扁平化
      firstOrder.subscribe(x => {console.log('flat',typeof x,x)}); //等价于嵌套效果,直接扁平化
    }
  }
</script>

<style scoped>

</style>
